<!DOCTYPE html>
<HTML>
<HEAD><meta name="viewport" content="width=device-width, initial-scale=1">
<Title>Heat Map Cell Labels</Title>
<link type='text/css' rel='Stylesheet' href="maxchartapi.css" />
</HEAD>
<body bgcolor="#FFFFFF" text="#000000" topmargin="0" leftmargin="0" rightmargin="0" marginwidth="0" marginheight="0">

<p class="heading0">ChartDirector 7.0 (Java Edition)</p>
<p class="heading1">Heat Map Cell Labels</p>
<hr class="separator">
<div class="content">
<img src="images/heatmapcelllabels.png" width='480' height='540'>
<br><br>
This example demonstrates adding labels to the cells, adding gaps between cells and using a custom color scale.<br><br>
This example is similar to <a href="discreteheatmap.htm">Discrete Heat Map</a>, with the following additions:<br><br>
<ul><li> Some cells are set to <a href="Chart.NoValue.htm">NoValue</a> to hide them.<br><br>
<li> <a href="Layer.setDataLabelFormat.htm">Layer.setDataLabelFormat</a> is used to set the cell labels to "{z|0}", which means to display the cell value with no decimal place. Please refer to <a href="paramsub.htm">Parameter Substitution and Formatting</a> for available formatting options.<br><br>
<li> <a href="DiscreteHeatMapLayer.setCellGap.htm">DiscreteHeatMapLayer.setCellGap</a> is used to configured the gaps between cells.<br><br>
<li> <a href="ColorAxis.setColorScale.htm">ColorAxis.setColorScale</a> is used to configured a custom color scale.</ul>
</div>
<p class="heading1a">Source Code Listing</p>
<div class="content">
<b>[JSP Version]</b> jspdemo/heatmapcelllabels.jsp
<div class='codeblock'><code class='pre'>&lt;%@page import="ChartDirector.*, java.util.*" %&gt;
&lt;%
// The x-axis and y-axis labels
String[] xLabels = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"};
String[] yLabels = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};

// Random data for the 10 x 10 cells
RanSeries rand = new RanSeries(2);
double[] zData = rand.get2DSeries(xLabels.length, yLabels.length, 0, 100);

// We set the middle 5 x 5 cells to NoValue to remove them from the chart
for(int x = 3; x &lt; 7; ++x) {
    for(int y = 3; y &lt; 7; ++y) {
        zData[y * xLabels.length + x] = Chart.NoValue;
    }
}

// Create an XYChart object of size 480 x 540 pixels.
XYChart c = new XYChart(480, 540);

// Set the plotarea at (50, 40) and of size 400 x 400 pixels. Set the background, border, and grid
// lines to transparent.
PlotArea p = c.setPlotArea(50, 40, 400, 400, -1, -1, Chart.Transparent, Chart.Transparent);

// Create a discrete heat map with 10 x 10 cells
DiscreteHeatMapLayer layer = c.addDiscreteHeatMapLayer(zData, xLabels.length);

// Set the x-axis labels. Use 8pt Arial Bold font. Set axis stem to transparent, so only the labels
// are visible. Set 0.5 offset to position the labels in between the grid lines. Position the x-axis
// at the top of the chart.
c.xAxis().setLabels(xLabels);
c.xAxis().setLabelStyle("Arial Bold", 8);
c.xAxis().setColors(Chart.Transparent, Chart.TextColor);
c.xAxis().setLabelOffset(0.5);
c.xAxis().setTitle("X axis title placeholder", "Arial Bold", 12);
c.setXAxisOnTop();

// Set the y-axis labels. Use 8pt Arial Bold font. Set axis stem to transparent, so only the labels
// are visible. Set 0.5 offset to position the labels in between the grid lines. Reverse the y-axis
// so that the labels are flowing top-down instead of bottom-up.
c.yAxis().setLabels(yLabels);
c.yAxis().setLabelStyle("Arial Bold", 8);
c.yAxis().setColors(Chart.Transparent, Chart.TextColor);
c.yAxis().setLabelOffset(0.5);
c.yAxis().setTitle("Y axis title placeholder", "Arial Bold", 12);
c.yAxis().setReverse();

// Set a 3-pixel gap between cells
layer.setCellGap(3);

// Use the z value as the cell label
layer.setDataLabelFormat("{z|0}");

// Position the color axis 20 pixels below the plot area and of the width as the plot area. Put the
// labels at the bottom side of the color axis. Use 8pt Arial Bold font for the labels.
ColorAxis cAxis = layer.setColorAxis(p.getLeftX(), p.getBottomY() + 20, Chart.TopLeft, p.getWidth(),
    Chart.Bottom);
cAxis.setLabelStyle("Arial Bold", 8);
cAxis.setTitle("Color legend title placeholder", "Arial Bold", 12);

// Set the color stops and scale of the color axis
double[] colorScale = {0, 0x00ff00, 50, 0xffff00, 80, 0xff6600, 100, 0xff0000};
cAxis.setColorScale(colorScale);
cAxis.setLinearScale(0, 100, 10);

// Output the chart
WebChartViewer viewer = new WebChartViewer(request, "chart1");
viewer.setChart(c, Chart.SVG);

// Include tool tip for the chart
viewer.setImageMap(c.getHTMLImageMap("", "", "title='&lt;*cdml*&gt;({xLabel}, {yLabel}) = {z|2}'"));
%&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Heat Map Cell Labels&lt;/title&gt;
    &lt;!-- Include ChartDirector Javascript Library to support chart interactions --&gt;
    &lt;script type="text/javascript" src="cdjcv.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body style="margin:5px 0px 0px 5px"&gt;
    &lt;div style="font:bold 18pt verdana;"&gt;
        Heat Map Cell Labels
    &lt;/div&gt;
    &lt;hr style="border:solid 1px #000080; background:#000080" /&gt;
    &lt;div style="font:10pt verdana; margin-bottom:1.5em"&gt;
        &lt;a href="viewsource.jsp?file=&lt;%=request.getServletPath()%&gt;"&gt;View Source Code&lt;/a&gt;
    &lt;/div&gt;
    &lt;!-- ****** Here is the chart image ****** --&gt;
    &lt;%= viewer.renderHTML(response) %&gt;
&lt;/body&gt;
&lt;/html&gt;</code></div>
</div>
<br><hr class="separator"><div class="copyright">&copy; 2022 Advanced Software Engineering Limited. All rights reserved.</div>
</body>
</HTML>
